﻿<!DOCTYPE html>
<html>

<head>
	<meta charset="UTF-8">
	<title>班牌机</title>
	<link rel="stylesheet" href="css/common2.css">
	<link rel="stylesheet" href="/css/layui.css" />
	<style>
		.school {
			margin-left: 2%;
			margin-top: 20px;
			display: inline-block;
		}

		.search_img,
		.add {
			margin-left: 2%;
			margin-top: 0;
			display: inline-block;
		}

		#vue-root> :first-child {
			margin-left: 0%;
		}
	</style>
</head>

<body class="main-body">
	<div id="vue-root" style="margin-top: 50px;">
		<div>
			<div class="add" v-if="able.add">
				<a href="board_item.html" style="color: white">添加班牌机</a>
			</div>
			<div class="refresh" onclick="location.reload()" style="margin-left: 0;">刷新</div>


			<div class="school" v-if="!isSchool">
				<select name="drop1" class="search" v-model="search.schoolId"
					style="position: absolute; right: 410px; margin-top: -28px;">
					<option :value="undefined">请选择学校</option>
					<option v-for="school in schools" :key="school.id" :value="school.id" v-text="school.name"></option>
				</select>
			</div>
			<div class="school">
				<select name="drop1" class="search" v-model="search.classesId"
					style="position: absolute; right: 255px; margin-top: -28px;">
					<option :value="undefined">请选择班级</option>
					<option v-for="classes in classess" :key="classes.id" :value="classes.id" v-text="classes.name">
					</option>
				</select>
			</div>
			<input class="search" placeholder="请输入设备号码" v-model="search.code"
				style="position: absolute; right: 100px; margin-top: -5px; height: 33px; max-width: 120px;">

			<img src="image/search.png" alt="" class="search_img" @click="getData0" height="35" width="35"
				style="position: absolute; right: 3%; margin-top: -5px;">
			<div class="table ">
				<table class="table_top">
					<thead>
						<tr>
							<th class="two">
								<input type="checkbox" class="check-box" v-model="all">
							</th>
							<th>序号</th>

							<th v-if="!isSchool">学校名称</th>
							<th>班级名称</th>
							<th>设备名称</th>
							<th>设备号</th>
							<th>刷新数据</th>
							<th class="three" v-if="able.edit||able.del">编辑/删除</th>
						</tr>
					</thead>
					<tbody id="list">
						<tr v-for="(board,index) in list" :key="board.id">
							<td>
								<input type="checkbox" class="check-box" v-model="board.checked">
							</td>
							<td><span v-text="index+1"></span></td>

							<td v-text="board.schoolName" v-if="!isSchool"></td>
							<td v-text="board.classesName"></td>
							<td v-text="board.name"></td>
							<td v-text="board.code"></td>
							<td>
								<button @click="refresh(board.code)">刷新数据</button>
							</td>
							<td class="three" v-if="able.edit||able.del">
								<div class="option">
									<div v-if="able.edit" class="edit-icon option-icon">
										<a :href="'board_item.html?id='+board.id"
											style="position: absolute; left: 20%; top: 30%;">
											<img class="img" src="image/edit.png" height="20" width="20"
												onmouseover="this.src='image/edit_light.png'"
												onmouseout="this.src='image/edit.png'" />
										</a>
									</div>
									<div v-if="able.del" class="delete-icon option-icon" @click="del([board.id])"
										style="right: 20%; top:30%;position: absolute;">
										<img class="img" src="../image/delete.png" height="20" width="20"
											onmouseover="this.src='image/delete_light.png'"
											onmouseout="this.src='image/delete.png'" />
									</div>
								</div>
							</td>
						</tr>
					</tbody>
				</table>
			</div>
		</div>

		<div class="delete" @click="batchDelete" v-if="total>1">批量删除</div>

		<ul class="pagination" v-if="pages>1">
			<li>
				<a v-if="pageNum!=1" @click="pageNum=1">«</a>
				<a class="pages-jump" v-if="pageNum!=1" @click="pageNum--">‹</a>
				<a v-text="pageNum"></a>
				<a class="pages-jump" v-if="pageNum!=pages" @click="pageNum++">›</a>
				<a v-if="pageNum!=pages" @click="pageNum=pages">»</a>
			</li>
			<li>
				<a v-text="pages"></a>

			</li>
		</ul>
		<div style="float: right;margin-bottom: 20px;" v-if="pages>1">
			总共{{total}}条记录
			<select class="ui-select init" style="height:32px" v-model="pageSize">
				<!--style="margin-top: 14px;"-->
				<option :value="10">每页10条</option>
				<option :value="30">每页30条</option>
				<option :value="100">每页100条</option>
			</select>
		</div>


	</div>


	<script src="/scriptZIP/qs.min.js"></script>
	<script src="/scriptZIP/vue.min.js"></script>
	<script src="/scriptZIP/axios.min.js"></script>
	<script src="/scriptZIP/dayjs.min.js"></script>
	<script src="/lib/laydate/laydate.js"></script>
	<script src="js/common.js"></script>
	<script src="js/list.js"></script>
	<script src="/js/auth_util.js"></script>

	<script>

		var app = new Vue(merge({
			data: {
				schools: [],
				classess: [],
				urls: {
					list: '/pc/board/list',
					del: '/pc/board/del'
				},
				isSchool: false,
			},
			created: function () {
				if (/school/.test(top.location.href)) {
					this.isSchool = true;
					this.search.schoolId = top_params().id;
				} else {
					var url = '/pc/school/all';
					if (/agent/.test(top.location.href)) {
						url += '/' + top_params().id;
						this.search.agentId = top_params().id;
					}

					axios.get(url).then(function (res) {
						this.schools = res.data;
					}.bind(this));
				}
				this.getData();
				abled('board', this);
			},
			methods: {
				format: function (time) {
					if (!time) return '';
					return dayjs(time).format('YYYY-MM-DD HH:mm:ss');
				},
				refresh: function (code) {
					axios.post('/pc/device/refresh', toFormParams({ code: code })).then(function (res) {
						if (res.data) alert('已发送请求');
						else alert('设备未连接。请检查设备网络连接');
					});
				},
			},
			watch: {
				'search.schoolId': function (newValue, oldValue) {
					if (newValue) {
						axios.get('/pc/classes/all/' + newValue).then(function (res) {
							this.classess = res.data;
						}.bind(this));
					}
				}
			}
		}));

	</script>


</body>

</html>